package com.ibeeking.found.msg.rest.controller.v1;

import com.ibeeking.found.common.enums.PublishStatusEnum;
import com.ibeeking.found.msg.rest.service.ISmsConfigService;
import com.ibeeking.found.msg.rest.service.ISysMsgConfigService;
import com.ibeeking.found.msg.service.common.param.SmsConfigParam;
import com.ibeeking.found.msg.service.common.param.SysMsgConfigParam;
import com.ibeeking.found.msg.service.common.query.SmsConfigQuery;
import com.ibeeking.found.msg.service.common.query.SysMsgConfigQuery;
import com.ibeeking.found.msg.service.common.vo.SmsConfigVO;
import com.ibeeking.found.msg.service.common.vo.SysMsgConfigVO;
import com.ibeeking.nematos.constants.enums.LogSourceEnum;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import com.ibeeking.nematos.utils.bean.BeanUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName SmsConfigController控制器
 * @Description
 * @Author ibeeking
 * @Date 2020-12-09 10:54
 **/
@RestController
@RequestMapping("/msg/sysMsgConfig/v1")
public class SysMsgConfigController {

    @Resource
    private ISysMsgConfigService sysMsgConfigServiceImpl;

    @Log(logSource = LogSourceEnum.TENANT_LOG,logType = OperateLogTypeEnum.QUERY, describe = "系统消息配置分页查询")
    @PostMapping(value = "/listAllConfig")
    public List<SysMsgConfigVO> listAllSysMsgConfig() {
        return sysMsgConfigServiceImpl.listAll();
    }

    @Log(logSource = LogSourceEnum.TENANT_LOG,logType = OperateLogTypeEnum.QUERY, describe = "消息配置列表")
    @PostMapping(value = "/effectiveList")
    public List<SysMsgConfigVO> effectiveList(@RequestBody SysMsgConfigQuery query) {
        SysMsgConfigQuery smsConfigQuery = BeanUtil.convertBean(query, SysMsgConfigQuery.class);
        smsConfigQuery.setPublishStatus(PublishStatusEnum.ENABLE.getValue());
        return sysMsgConfigServiceImpl.list(smsConfigQuery);
    }

    @Log(logSource = LogSourceEnum.TENANT_LOG,logType = OperateLogTypeEnum.MODIFY, describe = "消息配置修改")
    @PostMapping(value = "/modify")
    public Boolean modify(@RequestBody SysMsgConfigParam param) {
        return sysMsgConfigServiceImpl.modify(param);
    }

    @Log(logSource = LogSourceEnum.TENANT_LOG,logType = OperateLogTypeEnum.QUERY, describe = "消息配置查看")
    @PostMapping(value = "/view/{id}")
    public SysMsgConfigVO view(@PathVariable("id") Long id) {
        return sysMsgConfigServiceImpl.view(id);
    }

    @Log(logSource = LogSourceEnum.TENANT_LOG,logType = OperateLogTypeEnum.MODIFY, describe = "消息配置启用/禁用")
    @PostMapping(value = "/changePublishStatus/{id}/{status}")
    public Boolean changePublishStatus(@PathVariable("id") Long id, @PathVariable("status") Integer status) {
        return sysMsgConfigServiceImpl.changePublishStatus(id, status);
    }

}
